package com.example.springboot.service.impl;

import com.example.springboot.common.Result;
import com.example.springboot.mapper.LogsMapper;
import com.example.springboot.pojo.entity.Logs;
import com.example.springboot.pojo.entity.User;
import com.example.springboot.service.ILogsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class LogsServiceImpl implements ILogsService {

    @Autowired
    private LogsMapper logsMapper;

    @Override
    public Result pageLogs(Integer pageNum, Integer pageSize,String type, String username) {
        //设置分页数
        PageHelper.startPage(pageNum,pageSize);
        // 自定义查询
        List<Logs> logList = logsMapper.selectByUsername(type,username);

        Page page = (Page)logList;

        List result = page.getResult();
        long total = page.getTotal();
        HashMap<String, Object> map = new HashMap<>();
        map.put("result",result);
        map.put("total",total);

        return Result.success(map);
    }


    @Override
    public Result deleteUser(Long id) {
        logsMapper.deleteById(id);
        return Result.success();
    }

    @Override
    public Result deleteUsers(List<Long> ids) {
        logsMapper.deleteBatch(ids);
        return Result.success();
    }

    @Override
    public void add(Logs logs) {
        logsMapper.insert(logs);
    }
}
